const path=require("path");
const typescript=require("rollup-plugin-typescript2");
const commonjs=require("rollup-plugin-commonjs");
const babel=require("rollup-plugin-babel");
const mkPkg=require('./rollup-plugin-mk-packageJson');
const paths=require('../config/paths');
const clear=require("rollup-plugin-clear");
const nodeResolve = require('@rollup/plugin-node-resolve');
const extensions = ['.ts',".tsx",".js",".jsx"];
const postcss=require('rollup-plugin-postcss');
const inputOptions=(name,files,version)=>{
     const input={};
    const rootPath=path.join(paths.components,name);
    const libPath=path.join(paths.libOutput,name);
    files.forEach((item)=>{
        const itemPath=path.relative(rootPath,item);
        const fileNames=itemPath.split(".");
        let name=fileNames[0];
        if (fileNames.length>1){
            fileNames.pop();
            name=fileNames.join();
        }
        if (name&&!itemPath.endsWith("package.json")){
            input[name]=item;
        }
    })//遍历文件名
    return {
        input,
        plugins:[
            clear({
                targets: [libPath],
            }),
            typescript(),
            commonjs(),
            mkPkg({
                temPath:path.join(rootPath,"./package.json"),
                name,
                version
            }),
            babel({
                exclude: 'node_modules/**', // 只编译源代码
                runtimeHelpers: true,
                extensions,
            }),
            postcss({
                extract: true,
                modules:{
                    generateScopedName:`edu-cc_${name}_[local]`,
                },
                autoModules:false
            }),
        ]
    }
}

module.exports=inputOptions;